home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / praliases / praliases.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-21  |  2.3 KB  |  76 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted provided
  7.  * that: (1) source distributions retain this entire copyright notice and
  8.  * comment, and (2) distributions including binaries display the following
  9.  * acknowledgement:  ``This product includes software developed by the
  10.  * University of California, Berkeley and its contributors'' in the
  11.  * documentation or other materials provided with the distribution and in
  12.  * all advertising materials mentioning features or use of this software.
  13.  * Neither the name of the University nor the names of its contributors may
  14.  * be used to endorse or promote products derived from this software without
  15.  * specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  */
  20.  
  21. #ifndef lint
  22. char copyright[] =
  23. "@(#) Copyright (c) 1988 Regents of the University of California.\n\
  24.  All rights reserved.\n";
  25. static char sccsid[] = "@(#)praliases.c    5.5 (Berkeley) 6/1/90    %I% local";
  26. static char rcsid[] = "@(#)$Id: praliases.c,v 5.5.0.1 1991/05/21 19:26:05 paul Exp $";
  27. # ifdef    __GNUC__
  28. static    char    compiled[] = "compiled by gcc version "__VERSION__;
  29. # endif /* __GNUC__ */
  30. #endif /* not lint */
  31.  
  32. #include <sendmail.h>
  33.  
  34. int
  35. main(argc, argv)
  36.     int argc;
  37.     char **argv;
  38. {
  39.     extern char *optarg;
  40.     extern int optind;
  41.     static char *filename = "/usr/lib/aliases";
  42.     datum content, key, firstkey(), nextkey(), fetch();
  43.     int ch;
  44.  
  45.     while ((ch = getopt(argc, argv, "f:")) != EOF)
  46.         switch((char)ch) {
  47.         case 'f':
  48.             filename = optarg;
  49.             break;
  50.         case '?':
  51.         default:
  52.             fputs("usage: praliases [-f file]\n", stderr);
  53.             exit(EX_USAGE);
  54.         }
  55.     argc -= optind;
  56.     argv += optind;
  57.  
  58.     if (dbminit(filename) < 0)
  59.         exit(EX_OSFILE);
  60.     if (!argc)
  61.         for (key = firstkey(); key.dptr; key = nextkey(key)) {
  62.             content = fetch(key);
  63.             printf("%.*s:%.*s\n", key.dsize, key.dptr, content.dsize, content.dptr);
  64.         }
  65.     else for (; *argv; ++argv) {
  66.         key.dptr = *argv;
  67.         key.dsize = strlen(*argv) + 1;
  68.         content = fetch(key);
  69.         if (!content.dptr)
  70.             printf("%s: No such key\n", key.dptr);
  71.         else
  72.             printf("%s:%s\n", key.dptr, content.dptr);
  73.     }
  74.     exit(EX_OK);
  75. }
  76.